package com.eco.common.response;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel("基本响应实体")
public class BaseResponse<T> {
    @ApiModelProperty("响应信息")
    private String message;
    @ApiModelProperty("请求状态码(0表示请求成功,非0即请求失败)")
    private Integer code;
    @ApiModelProperty("响应数据")
    private T result;

    public BaseResponse() {
        this.message = ResponseCodeEnum.SUCCESS.getMessage();
        this.code = ResponseCodeEnum.SUCCESS.getCode();
    }

    public static <T> BaseResponse<T> instance() {
        BaseResponse<T> response = new BaseResponse<T>();
        return response;
    }

    public static <T> BaseResponse instanceErr() {
        BaseResponse response = new BaseResponse();
        response.setMsgCode(ResponseCodeEnum.ERROR.getCode());
        return response;
    }

    public String getMessage() {
        return this.message;
    }

    public Integer getCode() {
        return this.code;
    }

    public T getResult() {
        return this.result;
    }

    public void setMsg(final String msg) {
        this.message = msg;
    }

    public void setMsgCode(final Integer msgCode) {
        this.code = msgCode;
    }

    public void setData(final T data) {
        this.result = data;
    }

    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof BaseResponse)) {
            return false;
        } else {
            BaseResponse<?> other = (BaseResponse)o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                label47: {
                    Object this$code = this.getCode();
                    Object other$msgCode = other.getCode();
                    if (this$code == null) {
                        if (other$msgCode == null) {
                            break label47;
                        }
                    } else if (this$code.equals(other$msgCode)) {
                        break label47;
                    }

                    return false;
                }

                Object this$message = this.getMessage();
                Object other$msg = other.getMessage();
                if (this$message == null) {
                    if (other$msg != null) {
                        return false;
                    }
                } else if (!this$message.equals(other$msg)) {
                    return false;
                }

                Object this$result = this.getResult();
                Object other$data = other.getResult();
                if (this$result == null) {
                    if (other$data != null) {
                        return false;
                    }
                } else if (!this$result.equals(other$data)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof BaseResponse;
    }

    @Override
    public int hashCode() {
        boolean PRIME = true;
        int result = 1;
        Object $code = this.getCode();
        result = result * 59 + ($code == null ? 43 : $code.hashCode());
        Object $message = this.getMessage();
        result = result * 59 + ($message == null ? 43 : $message.hashCode());
        Object $result = this.getResult();
        result = result * 59 + ($result == null ? 43 : $result.hashCode());
        return result;
    }

    @Override
    public String toString() {
        return "BaseResponse(message=" + this.getMessage() + ", code=" + this.getCode() + ", result=" + this.getResult() + ")";
    }
}